package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;

import com.sky.server.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private AdminOrderService orderService;

    /**
     * 收索订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("conditionSearch")
    public Result<PageResult> getDetails(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info(ordersPageQueryDTO + "");
        PageResult pageResults = orderService.getDetails(ordersPageQueryDTO);
        return Result.success(pageResults);
    }

    /**
     * 各状态订单数量
     * @return
     */
    @GetMapping("statistics")
    public Result statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 订单明细
     * @param id
     * @return
     */
    @GetMapping("details/{id}")
    public Result<OrderVO> getDetailsById(@PathVariable Long id) {
        OrderVO orderVO = orderService.getDetailsById(id);
        return Result.success(orderVO);
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("complete/{id}")
    public Result<Object> completeById(@PathVariable Long id) {
        orderService.completeById(id);
        return Result.success();
    }
    @PutMapping("confirm")
    public Result<Object> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirmById(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("rejection")
    public Result<Object> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectionById(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("delivery/{id}")
    public Result<Object> deliveryById(@PathVariable Long id) {
        orderService.deliveryById(id);
        return Result.success();
    }

    @PutMapping("cancel")
    public Result<Object> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

}
